$(function () {
    initDatagrid();
    $("#queryButton").click(function () {
        //开始时间与结束时间的判断
        var beginTime = $("input[name=beginTime]").val();
        var endTime = $("input[name=endTime]").val();
        if(beginTime>endTime){
            if(!endTime){
                $.easyui.messager.show("结束时间不能为空");

            }else{
                $.easyui.messager.show("开始时间不能大于结束时间");
            }
            return;
        }
        $("#listTable").datagrid('load', $('#queryForm').serializeObject());
    })

});


// 表格内容初始化
function initDatagrid() {
    var url = $.util.getRequestJson('/json/consumeManage.tradeList.json');

    $('#listTable').datagrid({
        url: url,
        idField: 'id',
        fit: true,
        pageSize: 20,
        pagination: true,
        checkOnSelect: false,
        selectOnCheck: false,
        singleSelect: true,
        toolbar: '#toolbarButton',
        fitColumns: true,
        columns: [
            [
                {
                    field: 'orderNo',
                    title: '订单编号',
                    align: 'center',
                    width: 15
                },
                {
                    field: 'phone',
                    title: '客户手机号',
                    align: 'center',
                    width: 12,
                    formatter:function (value, row, index) {
                        return value.toString().substr(0,3)+"****"+value.toString().substr(7);
                    }
                },
                {
                    field: 'name',
                    title: '客户姓名',
                    align: 'center',
                    width: 12
                },
                {
                    field: 'expendScore',
                    title: '消费积分',
                    align: 'center',
                    width: 8
                },
                {
                    field: 'expendTime',
                    title: '消费时间',
                    align: 'center',
                    width: 15
                },
                {
                    field: 'status',
                    title: '账单状态',
                    align: 'center',
                    width: 12,
                    formatter: function (value, row) {
                        return value ? '已生成账单' : '未生成账单';
                    }
                },
                {
                    field: 'id',
                    title: '操作',
                    align: 'center',
                    width: 18,
                    formatter: function (value, row) {
                        aEl = '<a href=javascript:gatherScoreDetail("{0}"); class="easyui-tooltip " title="详情">详情</a>';

                        //格式化操作按钮
                        return $.string.format(aEl, row.id);
                    }
                }
            ]
        ]
    });
}

// 查看订单详情   收分记录id
function gatherScoreDetail(gatherScoreId) {

    var title = "详情";
    var url = $.util.getRootPath() + '/page/shopManager/gatherScore/gatherScoreDetail.html';
    url = url + '?id=' + gatherScoreId;
    var dialog = $.easyui.showDialog({
        iconCls: "",
        title: title,
        width: 550,
        height: 370,
        maximizable: true,
        href: url,
        topMost: true,
        enableSaveButton: false,
        closeButtonText: '关闭'
    });
}

